package com.countryside.service.impl;

import com.countryside.mapper.EmployeeWorkMapper;
import com.countryside.pojo.CompanyWork;
import com.countryside.pojo.EmployeeWork;
import com.countryside.pojo.query.EmployeeWorkQuery;
import com.countryside.service.EmployeeWorkService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.UUID;

@Service
public class EmployeeWorkServiceImpl implements EmployeeWorkService {

    @Autowired
    EmployeeWorkMapper employeeWorkMapper;

    @Override
    public PageInfo<EmployeeWork> listEmployeeWork(EmployeeWorkQuery employeeWorkQuery) {
        PageHelper.startPage(employeeWorkQuery.getPageNum(),employeeWorkQuery.getPageSize());
        return new PageInfo<EmployeeWork>(employeeWorkMapper.listEmployeeWork(employeeWorkQuery));
    }

    @Override
    public PageInfo<EmployeeWork> listEmployeeWorkBySearch(EmployeeWorkQuery employeeWorkQuery) {
        PageHelper.startPage(employeeWorkQuery.getPageNum(),employeeWorkQuery.getPageSize());
        return new PageInfo<EmployeeWork>(employeeWorkMapper.listEmployeeWorkBySearch(employeeWorkQuery));
    }

    @Override
    public int addEmployeeWork(EmployeeWork employeeWork) {
        //获取当前时间
        LocalDateTime localDateTime = LocalDateTime.now();
        employeeWork.setPublishTime(localDateTime.format(DateTimeFormatter.ISO_DATE));
        return employeeWorkMapper.addEmployeeWork(employeeWork);
    }

    @Override
    public EmployeeWork getEmployeeWork(String userId) {
        return employeeWorkMapper.getEmployeeWork(userId);
    }

    @Override
    public int updateEmployeeWork(EmployeeWork employeeWork) {
        return employeeWorkMapper.updateEmployeeWork(employeeWork);
    }

    @Override
    public List<EmployeeWork> queryEmployeeWorkByExpectedWork(String expectedWork) {
        return employeeWorkMapper.queryEmployeeWorkByExpectedWork(expectedWork);
    }

    @Override
    public List<EmployeeWork> queryEmployeeWorkByAddress(String address, @Nullable Integer start, @Nullable Integer limit) {
        return employeeWorkMapper.queryEmployeeWorkByAddress(address,start,limit);
    }

    @Override
    public EmployeeWork queryEmployeeByEmployeeId(Integer id) {
        return employeeWorkMapper.queryEmployeeByEmployeeId(id);
    }
}
